function generateJsPDFFontFile() {
  var jsFile = '';
  var fontName = document.getElementById('fontName').value;
  var fontStyle = document.getElementById('fontStyle').value;
  var createdFileName = fontName + '-' + fontStyle + '.ttf';

  jsFile += '(function (jsPDFAPI) {\n';
  jsFile += 'var font = \'' + window.loadedFileContents + '\';\n';
  jsFile += 'var callAddFont = function () {\n';
  jsFile += 'this.addFileToVFS(\'' + createdFileName + '\', font);\n';
  jsFile += 'this.addFont(\'' + createdFileName + '\', \'' + fontName + '\', \'' + fontStyle + '\');\n};\n';
  jsFile += 'jsPDFAPI.events.push([\'addFonts\', callAddFont])\n';
  jsFile += ' })(jsPDF.API);';

  var newJsfile = new File([jsFile], fontName + '-' + fontStyle + '.js', { type: 'text/plain;charset=utf-8' });
  saveAs(newJsfile);
}

function watchFile(){
  var opts = {
    on: {
      load: function (e, file) {
        window.loadedFile = file;
        document.getElementById('fontName').value = file.extra.nameNoExtension;

        var fileReader = new FileReader();
        fileReader.onload = function (e) {
          window.loadedFileContents = e.target.result;
          window.loadedFileContents = window.loadedFileContents.substr(window.loadedFileContents.indexOf('base64,') + 7)
        };
        fileReader.readAsDataURL(file);
      }
    }
  };
  FileReaderJS.setupInput(document.getElementById('file-input'), opts);
}